package com.ego.cart.controller;

import com.ego.cart.client.GoodsFeignClient;
import com.ego.cart.pojo.Cart;
import com.ego.cart.service.CartService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class CartController {

    @Resource
     private CartService cartService;


    @PostMapping
    public ResponseEntity<Void> addCart(@RequestBody Cart cart){
        cartService.add(cart);
        return ResponseEntity.ok().build();
    }
    @GetMapping
    public ResponseEntity<List<Cart>>getCart(){
        List<Cart>carts= cartService.findAll();
        return ResponseEntity.ok(carts);

    }
    @PutMapping
    public ResponseEntity<Void> updateNum(@RequestParam("skuId") Long skuId,
                                          @RequestParam("num") Integer num) {
        this.cartService.updateNum(skuId, num);
        return ResponseEntity.ok().build();
    }

}
